<include file="Public:page_header"/>

<!-- Page Body -->
<div class="page-body">
    <div class="danger">
        说明：
        <ul>
            <li>点击展开下级所属市区城市</li>
        </ul>
        修改规则：
        <ul>
            <li>点击显示修改运费编辑窗口，点保存后修改当前选择的城市及其所属的所有下级区属城市</li>
            <li>可先批量修改所有同级市区城市，再选择特定地区名修改单个地区运费</li>
        </ul>
        注意：
        <ul>
            <li>若运费与现有运费一致，则不做任何修改，包括所属下级地区</li>
            <li></li>
            <li></li>
        </ul>
    </div>
    <div class="row">
        <div class="col-xs-1 col-md-1">
        </div>
        <div class="col-xs-2 col-md-2">
            <volist name="data" id="vo">
                <div class="checkbox btn-default province" id="{$vo.id}" province="{$key}" onclick="province(this)">
                    <label>
                        <!--<input type="checkbox" name="province[]" id="{$vo.id}" value="{$vo.id}"-->
                        <!--<eq name="vo.is_checked" value="1">checked</eq>-->
                        <!--&gt;-->
                        <span class="text">{$vo.name}</span>
                    </label>
                </div>
            </volist>
        </div>
        <div class="col-xs-3 col-md-3 city-p">

        </div>
        <div class="col-xs-3 col-md-3 district-p">

        </div>
    </div>
</div>
<!-- /Page Body -->
<div id="popover88" style="display:none;">
    <div class="form-group">
        <label class="">借阅运费</label>
        <input type="number" class="form-control" name="price_rent" placeholder="运费" style="width:auto;">
    </div>
    <div class="form-group">
        <label class="">购书运费</label>
        <input type="number" class="form-control" name="price_buy" placeholder="运费">
    </div>
    <div class="form-group">
        <div>
            <button class="btn btn-palegreen" onclick="save()">保存</button>
        </div>
    </div>
</div>
<script>
    var data = {$data_json};
    var id;
    var did = '1';
    var price_rent;
    var price_buy;
    //选择-省
    function province(object) {
        $('.province').removeClass('btn-primary');
        $(object).addClass('btn-primary');

        $('.city-p').empty();
        $('.district-p').empty();

        id = $(object).attr('province');
        var html = '';
        var i = 0;
        $.each(data[id]['city'], function (name, value) {
            html += '<div class="checkbox btn-default mycity" onclick="city(this)" id="' + value.id + '" city="' + i + '">';
            html += '<label>';

            html += '<span class="text">' + value.name + '</span>';

            html += '</label>';
            html += '</div>';
            i++;
        });
        $('.city-p').append(html);
        edit(object);
    }
    //选择-市
    function city(object) {
        $('.mycity').removeClass('btn-primary');
        $(object).addClass('btn-primary');

        $('.district-p').empty();

        var city_id = $(object).attr('city');
        var html = '';
        var i = 0;
        $.each(data[id]['city'][city_id]['district'], function (name, value) {
            html += '<div class="checkbox  btn-default district" onclick="district(this)" id="' + value.id + '" district="' + i + '">';
            html += '<label>';
            html += '<span class="text">' + value.name + '</span>';
            html += '</label>';
            html += '</div>';
            i++;
        });
        $('.district-p').append(html);
        edit(object);
    }
    //选择-区
    function district(object) {
        $('.district').removeClass('btn-primary');
        $(object).addClass('btn-primary');
        edit(object);
    }

    //显示框
    function edit(object) {
        //清除旧
        did_n = $(object).attr('id');
//        if (did == did_n) {
//            $('#' + did).popover('destroy');
//            did = did_n;
//        } else {
//            $('#' + did).popover('destroy');
//            did = did_n;
//        }
        $('#' + did).popover('destroy');
        did = did_n;

        $.post("{:U('getPrice')}",{"id":did},function(data){
            if(data.status=='success'){
                //启用
                var options = {
                    title: '运费设置',
                    placement:'bottom',
                    content: ''
                };
                $('#' + did).popover(options);
                $('#' + did).popover('show');
                $('.popover-content').append(set());
                price_rent=data.data.price_rent;
                price_buy=data.data.price_buy;
                $('.popover-content [name="price_rent"]').val(price_rent);
                $('.popover-content [name="price_buy"]').val(price_buy);
            }else{
                log(data.data);
            }
        },"json");
    }

    function set(){
        return $('#popover88').html();
    }

    function save(){
        price_rent=$('.popover-content [name="price_rent"]').val();
        price_buy=$('.popover-content [name="price_buy"]').val();
        $.post("{:U('Area/dosave')}",{'id':did,'price_rent':price_rent,'price_buy':price_buy},function(data){
            if(data.status=='success'){
                alert(data.data);
            }else{
                alert(data.data);
            }
        },'json');
    }

</script>